<template>
    <div>
        <div style="padding: 30px">
            <div>我收到的投递信息</div>
        </div>


        <div class="position_manager_info_contain">
        <!--数据内容-->
        <div>
            <el-table
                    ref="multipleTable"
                    :data="tableData"
                    tooltip-effect="dark"
                    style="width: 100%"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>

                <el-table-column
                        label="投递人"
                        width="180"
                        prop="deliveryName">
                </el-table-column>

                <el-table-column
                        label="联系电话"
                        width="180"
                        prop="phone">
                </el-table-column>

                <el-table-column
                        prop="jobName"
                        label="投递岗位"
                        width="180">
                </el-table-column>

                <el-table-column
                        prop="jobDeptement"
                        label="所属部门"
                        width="180">
                </el-table-column>

                <el-table-column
                        prop="createTime"
                        label="投递时间"
                        width="180">
                </el-table-column>

                <el-table-column
                        prop="feedback"
                        label="职位反馈"
                        width="100">
                    <template slot-scope="scope">
                        <el-tag type="info" size="small" v-if="scope.row.feedback == 0">未反馈</el-tag>
                        <el-tag type="success" size="small" v-else-if="scope.row.feedback == 1">合适</el-tag>
                        <el-tag type="danger" size="small" v-else-if="scope.row.feedback == 2">不合适</el-tag>

                    </template>
                </el-table-column>


                <el-table-column
                        fixed="right"
                        label="操作"
                        width="300"
                >
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="queryResume(scope.row)">查看简历</el-button>
                        <el-button type="text" size="small" @click="downloadResume(scope.row)">下载简历</el-button>
                       <!-- <el-button type="text" size="small">移除</el-button>-->
                        <el-button type="text" size="small" @click="feedabckSuitable(scope.row)">合适</el-button>
                        <el-button type="text" size="small" @click="feedabckNotSuitable(scope.row)">不合适</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!--分页条-->
        <div style="text-align: center;margin-top: 15px">
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="pageSizes"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
    </div>

</template>

<script>
    import workjobApi from "@/api/workjobs/workjobApi";
    import pdfApi from "@/api/pfd/pdfApi";

    export default {
        inject:["reload"],
        name: "my-delivery-create-user-position",
        data(){
            return{
                tableData: [
                    // {
                    //     deliveryName:'牛一聪',
                    //     phone:'15127910138',
                    //     jobName:'Java开发工程师',
                    //     jobDeptement:'研发部',
                    //     createTime:'2020-02-02 18:00:00'
                    // }
                ],
                multipleSelection: [],  //多选框
                currentPage:1,          //分页设置
                pageSizes:[1,2,3,4],    //每一页显示的条目数
                total:5,                //总条数
                pageSize:2,             //总页数量
            }
        },

        mounted() {
            this.loadinit()
        },

        methods:{
            feedabckSuitable(obj){
                const deliveryId = obj.deliveryId
                const positionId = obj.positionId
/*
                console.log("positionId == >>",positionId)
                console.log("obj == >>",obj)*/

                const feedback = 1
                workjobApi.fit(deliveryId,positionId,feedback)
                .then(data => {
                    if (data.data.code == 0){
                        this.reload()
                    }
                })
            },

            feedabckNotSuitable(obj){
                const deliveryId = obj.deliveryId
                const positionId = obj.positionId
                const feedback = 2
                workjobApi.notFit(deliveryId,positionId,feedback)
                    .then(data => {
                        if (data.data.code == 0){
                            this.reload()
                        }
                    })
            },


            /*查看简历信息 Finish*/
            queryResume(object){
                const obj = {
                    filePath:object.resumePath.replaceAll('\\','\\\\')
                }

                pdfApi.getPathBase64(obj)
                .then(data =>{
                    console.log("data <<===>>",data)
                    let url = this.createDownloadFileUrl('pdf预览', data.data.data)
                    window.open(url)
                })
                .catch(err => {
                    Promise.reject(err)
                })
            },

            createDownloadFileUrl(fileName, file) {
                var blob = this.dataURLtoFile(
                    `data:application/pdf;base64,${file}`,
                    fileName
                ) // application/zip 需要改成要下载文件的类型
                blob.lastModifiedDate = new Date()
                blob.name = fileName
                return URL.createObjectURL(blob)
            },
            dataURLtoFile(dataurl, filename) {
                // 生成Blob
                var arr = dataurl.split(',')
                var mime = arr[0].match(/:(.*?);/)[1]
                var bstr = atob(arr[1])
                var n = bstr.length
                var u8arr = new Uint8Array(n)
                while (n--) {
                    u8arr[n] = bstr.charCodeAt(n)
                }
                return new Blob([u8arr], {type: mime})
            },




            /*下载简历*/
            downloadResume(object){
                console.log("downlioad resume ===>> ", object)
                pdfApi.downloadCompany(object.deliveryId)
                .then(data => {
                    //console.log("downloading ",data.data)
                    const link = document.createElement("a");
                    //let blob = new Blob([data.data], { type: "application/vnd.ms-excel" });//生成blob对象
                    let blob = data.data
                    //console.log(blob)
                    link.style.display = "none";
                    link.href = URL.createObjectURL(blob);
                    let fileName = object.resumePath.split("\\");
                    link.setAttribute("download",fileName[fileName.length-1]); //下载的文件名以及文件格式
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                })
            },

            loadinit(){

                const userId = JSON.parse(localStorage.getItem('user')).userId

                workjobApi.companyCountDeliver(userId,this.currentPage,this.pageSize)
                .then(data =>{
                    if (data.data.code === 0){
                        this.tableData = data.data.listdata
                        this.total = data.data.totalCount
                    }
                    console.log("data ====>>> ",data)
                })
                .catch(err =>{
                    Promise.reject(err)
                })
            },
            handleSelect(){

            },
            //多选框信息
            handleSelectionChange(){

            },
            //当选择每一页的size数量改变时候触发
            handleSizeChange(value){
                //console.log("SizeChange:",value)
                this.pageSize = value
                this.loadinit()
            },
            handleCurrentChange(value){
                //console.log("currentPage:",value)
                this.currentPage = value
                this.loadinit()
            },
        }
    }
</script>

<style scoped>

</style>
